package cn.rongdao.jrkabao.ui.cashadvance.uicomponent;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRCollection;
import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;

/**
 * Created by jack on 2017/11/4
 */

public class CashGoPayUIComponent extends LinearLayout {

    private TextView tvMoney;
    private TextView tvCashInfo;
    private ItemBankCardUIComponent llCreditCard;
    private ItemBankCardUIComponent llDepositCard;

    public CashGoPayUIComponent(Context context) {
        super(context);
    }

    public CashGoPayUIComponent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CashGoPayUIComponent(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        tvMoney = (TextView) findViewById(R.id.lcg_tv_money);
        tvCashInfo = (TextView) findViewById(R.id.lcg_tv_cash_info);
        llCreditCard = (ItemBankCardUIComponent) findViewById(R.id.lcg_credit_card);
        llDepositCard = (ItemBankCardUIComponent) findViewById(R.id.lcg_depodit_card);
        llCreditCard.setCardName("取现信用卡：");
        llDepositCard.setCardName("到账储蓄卡：");
    }

    public void setMoney(String money) {
        SpannableString ss = new SpannableString(FRCollection.appendAsString("到账：", money, ""));
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.c666666)), 0, 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new AbsoluteSizeSpan(16, true), 0, 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tvMoney.setText(ss);
    }

    public void setCashInfo(String backMoney, String serviceCharge, String payment) {
        if (FRString.isEmpty(backMoney)) {
            backMoney = "0.00";
        }
        if (FRString.isEmpty(serviceCharge)) {
            serviceCharge = "0.00";
        }
        if (FRString.isEmpty(payment)) {
            payment = "0.00";
        }
        String content = FRCollection.appendAsString("返现：", backMoney, "    手续费：", serviceCharge, "    支付：", payment, "");
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.cff7048)), 3,
                3 + backMoney.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.cff7048)),
                content.indexOf("费")+ 2, content.indexOf("支") -1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.cff7048)),
                content.lastIndexOf("：") + 1, content.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        tvCashInfo.setText(ss);
    }

    public void setCreditContent(String creditCard, String bankNumber, String imageUrl) {
        llCreditCard.setCashGoPayCardName(FRCollection.appendAsString(creditCard, "(", bankNumber, ")", ""), imageUrl);
    }

    public void setDepositContent(String depositCard, String bankNumber, String imageUrl) {
        llDepositCard.setCashGoPayCardName(FRCollection.appendAsString(depositCard, "(", bankNumber, ")", ""), imageUrl);
    }
}